package com.beetlestech.nfe.main.biz.com.impl;

import java.util.ArrayList;
import java.util.List;

import com.beetlestech.nfe.fw.core.biz.AbstractDBLogic;
import com.beetlestech.nfe.main.biz.com.HbVStudentList;
import com.beetlestech.nfe.main.biz.com.dto.VstudentinfolistInfoDTO;
import com.beetlestech.nfe.main.biz.constant.CommonConstant;
import com.beetlestech.nfe.main.biz.constant.CtgCodeConstant;
import com.beetlestech.nfe.main.biz.constant.HbMessageCode;
import com.beetlestech.nfe.main.db.base.StatementDTO;
import com.beetlestech.nfe.main.db.base.StatementUtil;
import com.beetlestech.nfe.main.db.constant.SQLConstant;
import com.beetlestech.nfe.main.db.view.VstudentinfolistDTO;
public class HbVStudentListImpl extends AbstractDBLogic implements HbVStudentList, CtgCodeConstant, HbMessageCode, CommonConstant, SQLConstant {

	@Override
	public VstudentinfolistInfoDTO[] getStudentList(String userName,
			String trueName, Integer sex, String email, String phone,
			Integer areaCity) {
		List<VstudentinfolistInfoDTO> studentList = new ArrayList<VstudentinfolistInfoDTO>();
		List<VstudentinfolistDTO> studentListDB = new ArrayList<VstudentinfolistDTO>();
		VstudentinfolistDTO vstudentinfolistDTO =new VstudentinfolistDTO();
		StatementDTO statementDTO = new StatementDTO();
		if(userName!=null && !userName.equals("")){
			StatementUtil.andWhere(statementDTO, VstudentinfolistDTO.COLUMN_USERNAME, StatementUtil.KEYWORD.LIKE ,userName);
		}
		if(trueName!=null &&!trueName.equals("")){
			StatementUtil.andWhere(statementDTO, VstudentinfolistDTO.COLUMN_TRUENAME, StatementUtil.KEYWORD.LIKE ,trueName);
		}
		if(sex!=-1){
			StatementUtil.andWhere(statementDTO, VstudentinfolistDTO.COLUMN_SEX, StatementUtil.KEYWORD.EQUAL ,sex);
		}
		if(email!=null && !email.equals("")){
			StatementUtil.andWhere(statementDTO, VstudentinfolistDTO.COLUMN_EMAIL, StatementUtil.KEYWORD.LIKE ,email);
		}
		if(phone!=null && !phone.equals("")){
			StatementUtil.andWhere(statementDTO, VstudentinfolistDTO.COLUMN_PHONE, StatementUtil.KEYWORD.LIKE ,phone);
		}
		if(areaCity!=0){
			StatementUtil.andWhere(statementDTO, VstudentinfolistDTO.COLUMN_AREACITY, StatementUtil.KEYWORD.EQUAL ,areaCity);
		}
//		if(school!=null &&!school.equals("")){
//			StatementUtil.andWhere(statementDTO, VstudentinfolistDTO.COLUMN_TRUENAME, StatementUtil.KEYWORD.LIKE ,school);
//		}
//		if(professional!=null &&!professional.equals("")){
//			StatementUtil.andWhere(statementDTO, VstudentinfolistDTO.COLUMN_TRUENAME, StatementUtil.KEYWORD.LIKE ,professional);
//		}
		vstudentinfolistDTO.set_dynamicWhereCondition(statementDTO.getSQLStatement());
		studentListDB=queryDAO.queryForObjectList(VstudentinfolistDTO.SQL_SEARCH, vstudentinfolistDTO);
		if(studentListDB==null || studentListDB.size()==0){
			createApplicationException("errMsg", "没找到要查询的信息");
		}else{
			for(VstudentinfolistDTO item:studentListDB){
				studentList.add(convertToVStudentListInfo(item));
			}
		}
		return studentList.toArray(new VstudentinfolistInfoDTO[studentList.size()]);
	}
	private VstudentinfolistInfoDTO convertToVStudentListInfo(VstudentinfolistDTO item){
		VstudentinfolistInfoDTO vadmininfolistInfoDTO = new VstudentinfolistInfoDTO();
		vadmininfolistInfoDTO.setprofessional(item.getprofessional());
		vadmininfolistInfoDTO.setschool(item.getschool());
		vadmininfolistInfoDTO.setacademic(item.getacademic());
		vadmininfolistInfoDTO.setareacity(item.getareacity());
		vadmininfolistInfoDTO.setbirthdayday(item.getbirthdayday());
		vadmininfolistInfoDTO.setbirthdaymonth(item.getbirthdaymonth());
		vadmininfolistInfoDTO.setbirthdayyear(item.getbirthdayyear());
		vadmininfolistInfoDTO.setemail(item.getemail());
		vadmininfolistInfoDTO.setphone(item.getphone());
		vadmininfolistInfoDTO.setsex(item.getsex());
		vadmininfolistInfoDTO.setusrid(item.getusrid());
		vadmininfolistInfoDTO.settruename(item.gettruename());
		vadmininfolistInfoDTO.setusername(item.getusername());
		vadmininfolistInfoDTO.setpassword(item.getpassword());
		return vadmininfolistInfoDTO;
	}
}
